<?php

namespace App\Http\Controllers\Api;

use App\Repositories\CouponRepository;

class CouponController extends MiniAppController
{
    private $couponRepo = null;

    public function __construct(CouponRepository $couponRepo)
    {
        parent::__construct();
        $this->couponRepo = $couponRepo;
    }

    /**
     * 列表
     */
    public function index()
    {
        $filter = request()->all();
        $filter['uid'] = UID;
        $filter['type'] = intval(request()->get("type", 1));

        $res = $this->couponRepo->getList($filter, 2, 1);

        return retSuc($res);
    }

    public function mapping_list()
    {
        $filter = request()->all();
        $filter['uid'] = UID;
        $res = $this->couponRepo->getMappingList($filter, 2, 1);
        return retSuc($res);
    }

    public function mapping()
    {
        $type = intval(request()->get("type", 1));
        $res = $this->couponRepo->getCanUseCoupon(UID, 0, $type);
        return retSuc($res);
    }

    public function gain($coupon_id = 0)
    {
        if (!$coupon_id)
            return retFail("参数错误");

        return $this->couponRepo->gainMapping($coupon_id, UID);
    }
}
